#include "stdafx.h"
#include "akmodel.h"
#include "akmainwindow.h"


AKMainWindow::AKMainWindow(QWidget *parent, Qt::WFlags flags)
	: QMainWindow(parent, flags)
	, mMainWidget(this)
{
	initialize();

	/// Creates QActions which represent specific user commands
	createActions();

	/// Creates the Menu Bar (File, Edit, View, ...)
	createMenus();

	/// Outer Interface
	createToolBars();

	/// Inner Interface
	createWidgets();

	/// Creates the Status Bar at the bottom of the Window
	createStatusBar();



}

AKMainWindow::~AKMainWindow()
{
}

void AKMainWindow::initialize()
{
	/// QStringList of file format filters.
	/// Ordered by relevance. Only file formats supported by the OpenCV library.
	mFormatFilters << tr("All Files (*.*)")
		<< tr("WAV Files (*.wav )");
		
}

/// \brief
///
///
///
/// \return Nothing
/// \sa
void AKMainWindow::createActions()
{
	/// "Open" Action
	openAct = new QAction(tr("&Open\tCTRL+O"), this);
	openAct->setShortcut(QKeySequence::Open);
	openAct->setStatusTip(tr("Open Files"));
	connect(openAct, SIGNAL(triggered()), this, SLOT(open()));

	/// "Exit" Action
	exitAct = new QAction(tr("E&xit\tCTRL+Q"), this);
	exitAct->setShortcut(QKeySequence(tr("CTRL+Q")));
	exitAct->setStatusTip(tr("Exit Swift"));
	connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));

	/// "About" Action
	aboutAct = new QAction(tr("&About"), this);
	aboutAct->setStatusTip(tr("About Swift"));
	connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
}

/// \brief
///
///
///
/// \return Nothing
/// \sa
void AKMainWindow::createMenus()
{
	/// "File" Menu
	fileMenu = menuBar()->addMenu(tr("&File"));
	fileMenu->addAction(openAct);
	fileMenu->addAction(exitAct);

	/// "Edit" Menu
	editMenu = menuBar()->addMenu(tr("&Edit"));

	/// "View" Menu
	viewMenu = menuBar()->addMenu(tr("&View"));
	viewMenu->addSeparator();

	/// "Help" Menu
	helpMenu = menuBar()->addMenu(tr("&Help"));
	helpMenu->addAction(aboutAct);
}

/// \brief
///
///
///
/// \return Nothing
/// \sa
void AKMainWindow::createToolBars()
{
}

/// \brief
///
///
///
/// \return Nothing
/// \sa
void AKMainWindow::createWidgets()
{
		//this->resize(600, 400);
		this->setCentralWidget(&mMainWidget);
		
		QGridLayout *mMainGridLayout = new QGridLayout(&mMainWidget);
		mMainGridLayout->layout()->SetMaximumSize;
		mMainGridLayout->setSpacing(6);
		mMainGridLayout->setContentsMargins(11, 11, 11, 11);
		mMainGridLayout->setObjectName(QString::fromUtf8("gridLayout"));

		//////////////////////////////////////////////////////////////////////////
		/// group box: file import (FI)
		mFIGroup = new QGroupBox(&mMainWidget);
		mFIGroup->setObjectName(QString::fromUtf8("groupBox_2"));
		mFIGroup->setTitle(QApplication::translate("AKMainWindowClass", "FileImport", 0, QApplication::UnicodeUTF8));
		
		mFIVerticalLayout = new QVBoxLayout(mFIGroup);
		mFIVerticalLayout->setSpacing(6);
		mFIVerticalLayout->setContentsMargins(11, 11, 11, 11);
		mFIVerticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));

		mFIImportButton = new QPushButton(mFIGroup);
		mFIImportButton->setObjectName(QString::fromUtf8("pushButton"));
		mFIImportButton->setText(QApplication::translate("AKMainWindowClass", "FileOpenDialog", 0, QApplication::UnicodeUTF8));

		mFIListView = new QListView(mFIGroup);
		mFIListView->setObjectName(QString::fromUtf8("listView"));
		
		mFIVerticalLayout->addWidget(mFIImportButton);	
		mFIVerticalLayout->addWidget(mFIListView);

		mMainGridLayout->addWidget(mFIGroup, 0, 0, 4, 1);

		//////////////////////////////////////////////////////////////////////////
		/// group box: file options (FO)
		mFOGroup = new QGroupBox(&mMainWidget);
		mFOGroup->setObjectName(QString::fromUtf8("groupBox"));
		QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
		sizePolicy.setHorizontalStretch(0);
		sizePolicy.setVerticalStretch(0);
		sizePolicy.setHeightForWidth(mFOGroup->sizePolicy().hasHeightForWidth());
		mFOGroup->setSizePolicy(sizePolicy);
		mFOGroup->setMaximumSize(QSize(16777215, 16777215));
		mFOGroup->setTitle(QApplication::translate("AKMainWindowClass", "FileOptions", 0, QApplication::UnicodeUTF8));

		mFOFormLayout = new QFormLayout(mFOGroup);
		mFOFormLayout->setSpacing(6);
		mFOFormLayout->setContentsMargins(11, 11, 11, 11);
		mFOFormLayout->setObjectName(QString::fromUtf8("formLayout"));
		mFOFormLayout->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);
		mFONameLabel = new QLabel(mFOGroup);
		mFONameLabel->setObjectName(QString::fromUtf8("label"));
		mFONameLabel->setText(QApplication::translate("AKMainWindowClass", "Name", 0, QApplication::UnicodeUTF8));

		mFONameLineEdit = new QLineEdit(mFOGroup);
		mFONameLineEdit->setObjectName(QString::fromUtf8("lineEdit"));

		mFOCategoryLabel = new QLabel(mFOGroup);
		mFOCategoryLabel->setObjectName(QString::fromUtf8("label_2"));
		mFOCategoryLabel->setText(QApplication::translate("AKMainWindowClass", "Category", 0, QApplication::UnicodeUTF8));

		mFOCategoryComboBox = new QComboBox(mFOGroup);
		mFOCategoryComboBox->setObjectName(QString::fromUtf8("comboBox"));

		mFOIconChooserLabel = new QLabel(mFOGroup);
		mFOIconChooserLabel->setObjectName(QString::fromUtf8("label_3"));
		mFOIconChooserLabel->setText(QApplication::translate("AKMainWindowClass", "IconChooser", 0, QApplication::UnicodeUTF8));

		mFOIconChooserDeclarativeView = new QDeclarativeView(mFOGroup);
		mFOIconChooserDeclarativeView->setObjectName(QString::fromUtf8("declarativeView"));
		sizePolicy.setHeightForWidth(mFOIconChooserDeclarativeView->sizePolicy().hasHeightForWidth());
		mFOIconChooserDeclarativeView->setSizePolicy(sizePolicy);
		
		mFOSaveOptionsButton = new QPushButton(mFOGroup);
		mFOSaveOptionsButton->setObjectName(QString::fromUtf8("pushButton_3"));
		mFOSaveOptionsButton->setText(QApplication::translate("AKMainWindowClass", "SaveOptions", 0, QApplication::UnicodeUTF8));
		
		mFOPathLabel = new QLabel(mFOGroup);
		mFOPathLabel->setObjectName(QString::fromUtf8("label_5"));
		mFOPathLabel->setText(QApplication::translate("AKMainWindowClass", "Path", 0, QApplication::UnicodeUTF8));
		
		mFOCurrentPathLabel = new QLabel(mFOGroup);
		mFOCurrentPathLabel->setObjectName(QString::fromUtf8("label_6"));
		mFOCurrentPathLabel->setText(QApplication::translate("AKMainWindowClass", "<path-placeholder>", 0, QApplication::UnicodeUTF8));
		
		mFOFormLayout->setWidget(0, QFormLayout::LabelRole, mFOPathLabel);
		mFOFormLayout->setWidget(0, QFormLayout::FieldRole, mFOCurrentPathLabel);
		mFOFormLayout->setWidget(1, QFormLayout::LabelRole, mFONameLabel);
		mFOFormLayout->setWidget(1, QFormLayout::FieldRole, mFONameLineEdit);
		mFOFormLayout->setWidget(2, QFormLayout::LabelRole, mFOCategoryLabel);
		mFOFormLayout->setWidget(2, QFormLayout::FieldRole, mFOCategoryComboBox);
		mFOFormLayout->setWidget(3, QFormLayout::LabelRole, mFOIconChooserLabel);
		mFOFormLayout->setWidget(3, QFormLayout::FieldRole, mFOIconChooserDeclarativeView);
		mFOFormLayout->setWidget(4, QFormLayout::FieldRole, mFOSaveOptionsButton);

		mMainGridLayout->addWidget(mFOGroup, 0, 1, 1, 1);

		//////////////////////////////////////////////////////////////////////////
		/// group box: mass categorizer (MC)
		
		mMCGroup = new QGroupBox(&mMainWidget);
		mMCGroup->setObjectName(QString::fromUtf8("groupBox_3"));
		mMCGroup->setTitle(QApplication::translate("AKMainWindowClass", "MassCategorizer", 0, QApplication::UnicodeUTF8));
		sizePolicy.setHeightForWidth(mMCGroup->sizePolicy().hasHeightForWidth());
		mMCGroup->setSizePolicy(sizePolicy);
		
		mMCFormLayout = new QFormLayout(mMCGroup);
		mMCFormLayout->setSpacing(6);
		mMCFormLayout->setContentsMargins(11, 11, 11, 11);
		mMCFormLayout->setObjectName(QString::fromUtf8("formLayout_2"));
		mMCFormLayout->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);
		
		mMCCategoryLabel = new QLabel(mMCGroup);
		mMCCategoryLabel->setObjectName(QString::fromUtf8("label_4"));
		mMCCategoryLabel->setText(QApplication::translate("AKMainWindowClass", "Category", 0, QApplication::UnicodeUTF8));

		mMCCategoryComboBox = new QComboBox(mMCGroup);
		mMCCategoryComboBox->setObjectName(QString::fromUtf8("comboBox_2"));

		mMCAssignCategoryButton = new QPushButton(mMCGroup);
		mMCAssignCategoryButton->setObjectName(QString::fromUtf8("pushButton_2"));
		mMCAssignCategoryButton->setText(QApplication::translate("AKMainWindowClass", "AddToCategory", 0, QApplication::UnicodeUTF8));
		
		mMCFormLayout->setWidget(0, QFormLayout::LabelRole, mMCCategoryLabel);
		mMCFormLayout->setWidget(0, QFormLayout::FieldRole, mMCCategoryComboBox);
		mMCFormLayout->setWidget(1, QFormLayout::SpanningRole, mMCAssignCategoryButton);

		mMainGridLayout->addWidget(mMCGroup, 1, 1, 1, 1);

		//////////////////////////////////////////////////////////////////////////
		/// group box: category import (CI)
		mCIGroup = new QGroupBox(&mMainWidget);
		mCIGroup->setTitle(QApplication::translate("AKMainWindowClass", "CategoryImporter", 0, QApplication::UnicodeUTF8));
		mCIGroup->setObjectName(QString::fromUtf8("groupBox_4"));
		
		mCIVerticalLayout = new QVBoxLayout(mCIGroup);
		mCIVerticalLayout->setSpacing(6);
		mCIVerticalLayout->setContentsMargins(11, 11, 11, 11);
		mCIVerticalLayout->setObjectName(QString::fromUtf8("verticalLayout_2"));
		
		mCIImportButton = new QPushButton(mCIGroup);
		mCIImportButton->setObjectName(QString::fromUtf8("pushButton_4"));
		mCIImportButton->setText(QApplication::translate("AKMainWindowClass", "ImportCategory", 0, QApplication::UnicodeUTF8));
		
		mCIVerticalLayout->addWidget(mCIImportButton);

		mMainGridLayout->addWidget(mCIGroup, 2, 1, 1, 1);

		//////////////////////////////////////////////////////////////////////////
		/// group box: create group (CG)
		
		mCGGroup = new QGroupBox(&mMainWidget);
		mCGGroup->setObjectName(QString::fromUtf8("groupBox_5"));
		mCGGroup->setTitle(QApplication::translate("AKMainWindowClass", "CreateGroup", 0, QApplication::UnicodeUTF8));

		mCGFormLayout = new QFormLayout(mCGGroup);
		mCGFormLayout->setSpacing(6);
		mCGFormLayout->setContentsMargins(11, 11, 11, 11);
		mCGFormLayout->setObjectName(QString::fromUtf8("formLayout_3"));
		
		mCGProfileLabel = new QLabel(mCGGroup);
		mCGProfileLabel->setObjectName(QString::fromUtf8("label_7"));
		mCGProfileLabel->setText(QApplication::translate("AKMainWindowClass", "UserProfileName", 0, QApplication::UnicodeUTF8));
	
		mCGProfileLineEdit = new QLineEdit(mCGGroup);
		mCGProfileLineEdit->setObjectName(QString::fromUtf8("lineEdit_2"));
		
		mCGProfileComboBoxLabel = new QLabel(mCGGroup);
		mCGProfileComboBoxLabel->setObjectName(QString::fromUtf8("label_28"));
		mCGProfileComboBoxLabel->setText(QApplication::translate("AKMainWindowClass", "In Profile", 0, QApplication::UnicodeUTF8));
		
		mCGProfileComboBox = new QComboBox(mCGGroup);
		mCGProfileComboBox->setObjectName(QString::fromUtf8("comboBox_18"));
		
		mCGCategoryLabel = new QLabel(mCGGroup);
		mCGCategoryLabel->setObjectName(QString::fromUtf8("label_8"));
		mCGCategoryLabel->setText(QApplication::translate("AKMainWindowClass", "CategoryName", 0, QApplication::UnicodeUTF8));

		mCGCategoryLineEdit = new QLineEdit(mCGGroup);
		mCGCategoryLineEdit->setObjectName(QString::fromUtf8("lineEdit_3"));
	
		mCGCreateCategoryButton = new QPushButton(mCGGroup);
		mCGCreateCategoryButton->setObjectName(QString::fromUtf8("pushButton_6"));
		mCGCreateCategoryButton->setText(QApplication::translate("AKMainWindowClass", "CreateCategory", 0, QApplication::UnicodeUTF8));
		
		mCGCreateProfileButton = new QPushButton(mCGGroup);
		mCGCreateProfileButton->setObjectName(QString::fromUtf8("pushButton_5"));
		mCGCreateProfileButton->setText(QApplication::translate("AKMainWindowClass", "CreateUserProfile", 0, QApplication::UnicodeUTF8));

		mCGFormLayout->setWidget(0, QFormLayout::LabelRole, mCGProfileLabel);
		mCGFormLayout->setWidget(0, QFormLayout::FieldRole, mCGProfileLineEdit);
		mCGFormLayout->setWidget(1, QFormLayout::SpanningRole, mCGCreateProfileButton);
		mCGFormLayout->setWidget(2, QFormLayout::LabelRole, mCGProfileComboBoxLabel);
		mCGFormLayout->setWidget(2, QFormLayout::FieldRole, mCGProfileComboBox);
		mCGFormLayout->setWidget(3, QFormLayout::LabelRole, mCGCategoryLabel);
		mCGFormLayout->setWidget(3, QFormLayout::FieldRole, mCGCategoryLineEdit);
		mCGFormLayout->setWidget(4, QFormLayout::SpanningRole, mCGCreateCategoryButton);

		mMainGridLayout->addWidget(mCGGroup, 3, 1, 1, 1);

		//////////////////////////////////////////////////////////////////////////
		/// group box: abstract model (AM)

		mAMGroup = new QGroupBox(&mMainWidget);
		mAMGroup->setObjectName(QString::fromUtf8("groupBox_6"));
		mAMGroup->setTitle(QApplication::translate("AKMainWindowClass", "AbstractListModel", 0, QApplication::UnicodeUTF8));

		mAMVerticalLayout = new QVBoxLayout(mAMGroup);
		mAMVerticalLayout->setSpacing(6);
		mAMVerticalLayout->setContentsMargins(11, 11, 11, 11);
		mAMVerticalLayout->setObjectName(QString::fromUtf8("verticalLayout_3"));
		
		mAMUpdateButton = new QPushButton(mAMGroup);
		mAMUpdateButton->setObjectName(QString::fromUtf8("pushButton_7"));
		mAMUpdateButton->setText(QApplication::translate("AKMainWindowClass", "Update", 0, QApplication::UnicodeUTF8));

		mAMListView = new QListView(mAMGroup);
		mAMListView->setObjectName(QString::fromUtf8("listView_2"));

		mAMVerticalLayout->addWidget(mAMUpdateButton);
		mAMVerticalLayout->addWidget(mAMListView);

		mMainGridLayout->addWidget(mAMGroup, 0, 2, 4, 1);
}

/// \brief
///
///
///
/// \return Nothing
/// \sa
void AKMainWindow::createStatusBar()
{
	statusBar()->showMessage(tr("Ready"));
}

/// \brief
///
///
///
/// \return Nothing
/// \sa
void AKMainWindow::open()
{
	/// file open dialog to import images into the sign recognition software.
	/// it supports a multitude of file formats (see "filters").
	mNewImportPaths = QFileDialog::getOpenFileNames(
		this,
		tr("Open File(s)"),
		QDir::currentPath().append("/TestData"),
		mFormatFilters.join(";;"),
		&mFormatFilters[1],
		nullptr
		);

	/// wrong user input might cause duplicate file paths in the "input"
	/// string list. not exactly sure but we better be safe. we got the
	/// processing power :-D
	mNewImportPaths.removeDuplicates();

	/// remove redundant paths from the new "input" string list.
	/// redundant are paths which are already elements of the "paths"
	/// string list.
	for ( QStringList::Iterator it = mNewImportPaths.begin(); it != mNewImportPaths.end(); ++it )
	{
		if (mImportPaths.contains(*it)) ///< pointer-style iterator dereference
		{
			it = mNewImportPaths.erase(it);
		}
	}

	//mSwiftModel.loadFiles(mNewImagePaths); ///< load all new and non duplicate images
	//mAllImagePaths += mNewImagePaths; ///< add the new input to the "paths" member
}

void AKMainWindow::about()
{
	AKModel akmodel =new AKModel;
	//akmodel.load("C:/Users/Matze/Desktop/Games/Rpg Maker/Eternal Legends/Sound/Fire.wav");
	akmodel.load("D:/STUDIUM/Sem6/InteraktiveSysteme/svn/armyknive/Fire.wav");
	QMessageBox::about(this, tr("TMP"),
		tr("TMP"));
}